package org.example.springboot.controller;

import org.example.springboot.model.Items;
import org.example.springboot.service.ItemsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RestController
public class ItemsController {
    @Autowired
    private ItemsService itemsService;

    @PostMapping("/insertItem")
    public String insertItem(@RequestBody Items items){
        return itemsService.insertItem(items.getProjectName(),items.getProjectLeader(),items.getContactPhone(),items.getSalesTeam(),items.getSalesContactPhone(),items.getAfterSalesTeam(),items.getAfterSalesContactPhone(),items.getProjectDescription(),items.getCostDescription());
    }

    @GetMapping("/getAllItems")
    public List<Items> getAllItems(){
        return itemsService.getAllItems();
    }

    @GetMapping("/findItemByKeyword/{keyword}")
    public List<Items> findItemByKeyword(@PathVariable String keyword){
        return itemsService.findItemByKeyword(keyword);
    }

    @DeleteMapping("/deleteItemById/{id}")
    public void deleteById(@PathVariable int id){
        itemsService.deleteItemById(id);
    }


    @GetMapping("/findItemById/{id}")
    public Items findItemById(@PathVariable int id){
        return itemsService.findItemById(id);
    }
}
